package com.neusoft.yiyang.user.controller;

import com.neusoft.yiyang.common.entity.user.Role;
import com.neusoft.yiyang.user.service.RoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "系统角色管理接口", description = "负责系统角色的增删改查，维护用户权限体系的基础单元")
@RestController
@RequestMapping("/roles")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @Operation(summary = "获取所有角色", description = "查询系统中所有未删除的角色信息（逻辑删除的角色不返回）")
    @GetMapping
    public List<Role> getAllRoles() {
        return roleService.getAllRoles();
    }

    @Operation(summary = "根据ID查询角色", description = "获取指定ID的角色详细信息")
    @GetMapping("/{id}")
    public Role getRoleById(
            @Parameter(description = "角色ID", required = true)
            @PathVariable("id") Integer id) {
        return roleService.getRoleById(id);
    }

    @Operation(summary = "创建角色", description = "新增系统角色（含角色名称、描述、权限等信息）")
    @PostMapping
    public void createRole(
            @Parameter(description = "角色信息（含角色名称、描述等）", required = true)
            @RequestBody Role role) {
        roleService.createRole(role);
    }

    @Operation(summary = "更新角色", description = "修改已存在角色的信息（如角色名称、权限范围等）")
    @PutMapping("/{id}")
    public void updateRole(
            @Parameter(description = "角色ID", required = true) @PathVariable("id") Integer id,
            @Parameter(description = "更新后的角色信息", required = true) @RequestBody Role role) {
        role.setRoleId(id);
        roleService.updateRole(role);
    }

    @Operation(summary = "删除角色", description = "逻辑删除指定ID的角色（标记为已删除，不实际物理删除）")
    @DeleteMapping("/{id}")
    public void deleteRole(
            @Parameter(description = "角色ID", required = true) @PathVariable("id") Integer id) {
        roleService.deleteRole(id);
    }
}